<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1" placeholder="请输入0-100的整数">
<input type="button" value="猜一猜" onclick="fn()">
<div id="d1"></div>
<div id="d2"></div>
<script>
    let x = parseInt(Math.random()*101);
    let num = 0;
    console.log(x);  //控制台打印
    function fn(){
        //NaN: Not a Number 不是一个数
        if (isNaN(i1.value)||i1.value.trim()==""){
            d1.innerText="输入错误！"
            return;
        }
        num+=1;
        if (i1.value>x){
            d1.innerText = "猜大了！"
        }
        else if (i1.value<x){
            d1.innerText = "猜小了！"
        }
        else {
            d1.innerText = "恭喜你，猜对了！"
            d2.innerText = "已猜次数："+num;
        }
    }


</script>
</body>
</html>